﻿using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
//using Common;
using Newtonsoft.Json;
using System.Xml;


public class DataManager : Singleton<DataManager>
{
    public string DataPath;

    //public Dictionary<int, MapDefine> Maps = null;

    public DataManager()
    {
        this.DataPath = "Data/";
        Debug.LogFormat("DataManager > DataManager()");
    }
    public void Load()
    {
/*
        string json = File.ReadAllText(this.DataPath + "MapDefine.txt");
        this.Maps = JsonConvert.DeserializeObject<Dictionary<int, MapDefine>>(json);
*/
       
    }

    public IEnumerator LoadData()
    {
        /*
        string json = File.ReadAllText(this.DataPath + "NpcDefine.txt");
        this.Maps = JsonConvert.DeserializeObject<Dictionary<int, MapDefine>>(json);
        */
     
        yield return null;

    }


    public void SaveByJson(string saveFileName, string data)
    {
        var path = Path.Combine(this.DataPath, saveFileName);
        Debug.Log(path);
        try
        {
            File.WriteAllText(path, data);
            Debug.Log("Warn");
        }
        catch (System.Exception exception)
        {
            Debug.LogError($"Failed to save data to {path}.\n{exception}");
        }
    }

    public void OnSaveLoad()
    {
        /*
       string json = File.ReadAllText(this.DataPath + "Save.txt");
       this.Tests = JsonConvert.DeserializeObject<TestDefine>(json);
         */
    }
#if UNITY_EDITOR

    public void SaveSpawnPoints()
    {
        //string json = JsonConvert.SerializeObject(this.SpawnPoints, Formatting.Indented);
        //File.WriteAllText(this.DataPath + "SpawnPointDefine.txt", json);
    }

#endif
}